package cn.chenfeifx.media.controls;

import cn.chenfeifx.media.controls.skin.MediaPlayerSliderSkin;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.Cursor;
import javafx.scene.control.Control;
import javafx.scene.control.Skin;

public class MediaPlayerSlider extends Control {

    public MediaPlayerSlider() {
        setCursor(Cursor.HAND);
        setPrefHeight(10);
        setMaxSize(USE_COMPUTED_SIZE, USE_PREF_SIZE);
    }

    public MediaPlayerSlider(double min, double max, double value) {
        this();
        setNumber(min, max, value);
    }

    public void setNumber(double min, double max, double value) {
        setMin(min);
        setMax(max);
        setValue(value);
    }

    private final DoubleProperty min = new SimpleDoubleProperty(0);

    public double getMin() {
        return min.get();
    }

    public DoubleProperty minProperty() {
        return min;
    }

    public void setMin(double min) {
        this.min.set(min);
    }

    private final DoubleProperty max = new SimpleDoubleProperty(1);

    public double getMax() {
        return max.get();
    }

    public DoubleProperty maxProperty() {
        return max;
    }

    public void setMax(double max) {
        this.max.set(max);
    }

    private final DoubleProperty value = new SimpleDoubleProperty(0);

    public double getValue() {
        return value.get();
    }

    public DoubleProperty valueProperty() {
        return value;
    }

    public void setValue(double value) {
        this.value.set(value);
    }

    private final ObjectProperty<Mode> mode = new SimpleObjectProperty<>(Mode.RELEASED);

    public Mode getMode() {
        return mode.get();
    }

    public ObjectProperty<Mode> modeProperty() {
        return mode;
    }

    public void setMode(Mode mode) {
        this.mode.set(mode);
    }

    private final DoubleProperty arc = new SimpleDoubleProperty(4);

    public double getArc() {
        return arc.get();
    }

    public DoubleProperty arcProperty() {
        return arc;
    }

    public void setArc(double arc) {
        this.arc.set(arc);
    }

    @Override
    protected Skin<?> createDefaultSkin() {
        return new MediaPlayerSliderSkin(this);
    }

    /**
     * 值的更新方式
     */
    public enum Mode {

        /**
         * 鼠标释放更新值
         */
        RELEASED,

        /**
         * 任何操作都会更新值
         */
        ANY;
    }

}
